import { UserCouponStatus } from "@/constants/enums/coupon"
import request from "@/utils/request"
import request2 from "@/utils/request2";

export async function queryCouponList(params: Coupon.QueryListParams) {
  return request<Coupon.Entity[]>('/app/manager/couponModuleList', {
    data: params,
  })
}

export async function getCouponDetail(params: {id: string}) {
  return request<Coupon.Entity>('/app/manager/couponModule/detail', {
    data: params,
  })
}

export async function addCouponTemplate(params: Partial<Coupon.Entity>) {
  return request<number>('/app/manager/addCouponModule', {
    data: params,
  })
}

export async function delCoupon(params: {
  id: string, 
  status: 1 | 2 | 3, // 1:上架中, 2:待上架, 3:接触券包关联
}) {
  return request('/app/manager/statusCouponModule', {
    data: params,
  })
}

export async function queryUserCouponList(params: Coupon.QueryUserCouponListParams) {
  return request<Coupon.UserCoupon[]>('/app/manager/userCouponList', {
    data: params,
  })
}

export async function queryUserGoodsCouponList(params: {userId: string, status?: UserCouponStatus}) {
  return request2<Goods.MallCoupon[]>(`/api/mall/manage/coupon/user/${params.userId}`, {
    method: 'GET',
    data: params.status ? {
      state: params.status
    } : undefined,
  })
}

export async function queryCouponPackageList(params: PaginationParams) {
  return request<Coupon.CouponPackage[]>('/app/manager/couponModulePackage/list', {
    data: params,
  })
}

export async function delCouponPackage(params: {id: string}) {
  return request('/app/manager/couponModulePackage/upStatus', {
    data: params,
  })
}

export async function queryCouponPackageGetList(params: {id?: string} & PaginationParams) {
  return request<Coupon.CouponPackage[]>('/app/manager/couponModulePackage/get/list', {
    data: params,
  })
}

export async function queryCouponPackageDetail(params: {id?: string}) {
  return request<Coupon.CouponPackage>('/app/manager/couponModulePackage/detail', {
    data: params,
  })
}

export async function saveCouponPackage(params: Partial<Coupon.CouponPackage>) {
  return request<string>('/app/manager/couponModulePackage/addOrUp', {
    data: params,
  })
}

export async function generateCouponCode(params: {id: string, num: number}) {
  return request('/app/manager/coupon/batch', {
    data: params,
  })
}
